<?php 

Yii::app()->clientScript->registerCssFile('css/InvoiceReport.css'); 
Yii::app()->clientScript->registerCoreScript('jquery');
?>
<div id="invoice-report">
    <div id="create-date">
        <?php echo date('Y-m-d'); ?>
        <br/>
        <?php echo date('H:i:s'); ?>
    </div>

    <div id="title">
        <b>Weekly Report</b>
        <br/>
        
    </div>
    
    <script>
        $(document).ready(function(){
            
            $('.salesOrderRow').hide();            
            $('#showSalesOrderList').click(function(){                
               $('.salesOrderRow').toggle();
            })
            $('.uninvoiceContractRow').hide();
            $('#uninvoice-contract-list').click(function(){
                $('.uninvoiceContractRow').toggle();
            })
            
            $('.contracttypelist').hide();
            $('.contracttype').click(function(){
                $(this).parent().parent().next().find('td').toggle();
            })
        })
    </script>
    <div id="content">
        <?php
        $table = new CI_Table();
        $table->set_template(array(
            'table_open'=>'<table style="width:500px";>',
            'cell_start'=>'<td style="border:none">',
            'heading_cell_start'=>'<td style="border:none">',
            'cell_alt_start'=>'<td style="border:none;">',
        ));
        $emptyLine='___________________';
        $table->add_row('<div class="entry-title">UNEARNED REVENUE</div>','');
        $table->add_row('<div id="uninvoice-contract-list" class="entry">Pre-Quote Contracts</div>','');
        $table->add_row(array(
            'data'=>$this->renderPartial('_uninvoiceContract',array(
                'uninvoiceContractList'=>$uninvoiceContractList
            ),true),
            'colspan'=>2,
            'class'=>'uninvoiceContractRow'
        ));
        foreach(ContractType::getListData() as $key=>$value){
            $table->add_row("<div class='contracttype subentry'>$value</div>",  number_format($uninvoiceContractListByType[$key]['total'],2));
            $table->add_row(array(
                'data'=>$this->renderPartial('_uninvoiceContract',array(
                    'uninvoiceContractList'=>$uninvoiceContractListByType[$key]['list']
                ),true),
                'colspan'=>2,
                'class'=>'contracttypelist '
            ));
        }
        $table->add_row('',$totalUninvoiceContract);
        
        //////////
        $table->add_row('<div id="showSalesOrderList" class="entry">Sales Orders</div>','');
        $table->add_row(array(
            'data'=> $this->renderPartial('_salesOrderList',array(
                'salesOrderList'=>$salesOrderList,
                'salesOrderInvoiceList'=>$salesOrderInvoiceList
            ),true),
            'colspan'=>2,
            'class'=>'salesOrderRow'
        ));
        foreach($salesOrderListByType as $key=>$value){
            $table->add_row("<div class='subentry contracttype'>$key</div>",number_format($value,2));
            $table->add_row(array(
                'data'=>$this->renderPartial('_salesOrderListByDept',array(
                    'salesOrderList'=>$salesOrderDeptList[$key]
                ),true),
                'colspan'=>2,
                'class'=>'contracttypelist'
            ));
        }                
        $table->add_row('',$totalSalesOrder);
        
        //////
        $table->add_row("<div class='entry-title'>RECEIVABLES</div>",'');
       // $table->add_row('&nbsp','&nbsp');
        
        $table->add_row("<div class='entry'>Not Inputed</div>",$emptyLine);
        $table->add_row("<div class='entry'>QuickBooks A/R",$emptyLine);
        
        $table->add_row("<div class='entry'>Invoices",'');
        
        foreach($invoiceTotalByDepartment as $key=>$value){
            $table->add_row("<div class='subentry'>".SalesDepartments::getText($key).'</div>',number_format($value,2));
        }
        $table->add_row('',$totalInvoice);
        $table->add_row("<div class='entry'>Register",$emptyLine);
        
        $table->add_row('&nbsp','&nbsp');
        
        $table->add_row("<div class='entry-title'>PAYABLES</div>",'');
        $table->add_row("<div class='entry'>Total Install Cost</div>",$emptyLine);
        $table->add_row("<div class='entry'>QB Bills</div>",$emptyLine);
        $table->add_row('&nbsp','&nbsp');
        
        $table->add_row("<div class='entry-title'>SUB-TOTALS</div>",'');
        $table->add_row("<div class='entry'>Total Receivables</div>",$emptyLine);
        $table->add_row("<div class='entry'>Total Payables</div>",$emptyLine);
        $table->add_row('&nbsp','&nbsp');
        
        $table->add_row("<div class='entry-title'>TOTAL</div>",$emptyLine);
        echo $table->generate();
        ?>

    </div>

    


</div>